﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Security.Cryptography;
using System.IO;

namespace Client
{
   public class SporeXML:XmlDocument
    {
       private DES des;
       byte[] key = new byte[] {0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
       byte[] vi = new byte[] { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28 };
       public SporeXML()
       {
           this.des = DES.Create();
       }
       public override void Load(string filename)
       {
           FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
           CryptoStream cryptoStream = new CryptoStream(fileStream, des.CreateDecryptor(key, vi), CryptoStreamMode.Read);
           base.Load(cryptoStream);
           cryptoStream.Close();
           fileStream.Close();
       }
       public override void Save(string filename)
       {
           FileStream fileStream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
           ICryptoTransform itf=  des.CreateEncryptor();
           CryptoStream cryptoStream = new CryptoStream(fileStream, des.CreateEncryptor(key,vi), CryptoStreamMode.Write);
           base.Save(cryptoStream);
           cryptoStream.FlushFinalBlock();
           cryptoStream.Close();
           fileStream.Close();
       }
    }
}
